package com.yun2.bms.service.impl;

import com.yun2.bms.dao.ICategoryDao;
import com.yun2.bms.dao.impl.CategoryDaoImpl;
import com.yun2.bms.model.Category;
import com.yun2.bms.service.ICategoryService;

import java.util.List;

/**
 * author: youli
 * qq: 27855162@qq.com
 * date: 2020/5/26
 */

public class CategoryServiceImpl implements ICategoryService {

    private ICategoryDao categoryDao = new CategoryDaoImpl();

    @Override
    public List<Category> getAll() {
        return this.categoryDao.getAll();
    }

    @Override
    public Category get(int id) {
        return this.categoryDao.get(id);
    }

    @Override
    public int delete(List<Category> list) {
        String ids = "";
        //将list集合转换为字符串形式，27,27,28,29,29
        for(Category category : list){
            ids += category.getId();
            ids += ",";
        }
        ids = ids.substring(0, ids.length()-1);

        return this.delete(ids);
    }

    /**
     * 删除多条记录
     * @param ids:27,28,29
     * @return
     */
    @Override
    public int delete(String ids) {
        return this.categoryDao.delete(ids);
    }

    @Override
    public List<Category> getAllByCategoryName(String categoryName) {
        return this.categoryDao.getAllByCategoryName(categoryName);
    }

    @Override
    public boolean isCategoryNameUnique(String categoryName) {
        return this.categoryDao.isCategoryNameUnique(categoryName);
    }

    @Override
    public boolean isCategoryNameUnique(Integer id, String categoryName) {
        return this.categoryDao.isCategoryNameUnique(id, categoryName);
    }

    @Override
    public int edit(Category category) {
        return this.categoryDao.edit(category);
    }

    @Override
    public int add(Category category) {
        return this.categoryDao.add(category);
    }

}
